//
//  KongWIllnessDetailTableViewCell.m
//  LoveOfPet
//
//  Created by dllo on 15/11/23.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "KongWIllnessDetailTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
#define kHeight     [UIScreen mainScreen].bounds.size.height / 667
#define kWidth      [UIScreen mainScreen].bounds.size.width / 375
@interface KongWIllnessDetailTableViewCell ()
@property (retain, nonatomic) UIImageView *upImg;
@end
@implementation KongWIllnessDetailTableViewCell
- (void)dealloc
{
    [_illnessDetailModel release];
    [_img release];
    [_titleLabel release];
    [_upImg release];
    [_upLabel release];
    [super dealloc];
}
-(instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubView];
    }
    return self;
}
-(void)creatSubView
{
    self.img = [[UIImageView alloc] init];
    [self.contentView addSubview:self.img];
    [self.img release];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel release];
    
    self.upLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.upLabel];
    [self.upLabel release];
    
    self.upImg = [[UIImageView alloc] init];
    [self.contentView addSubview:self.upImg];
    [self.upImg release];
}

-(void)layoutSubviews
{
    self.img.frame = CGRectMake(kWidth * 10, kHeight * 10, self.frame.size.height - kHeight * 10, self.frame.size.height - kHeight * 10);
    
    self.titleLabel.frame = CGRectMake(self.img.frame.origin.x + self.img.frame.size.width + kWidth * 10, self.img.frame.origin.y, self.frame.size.width - self.img.frame.origin.x - self.img.frame.size.width - kWidth * 20, kHeight * 30);
    
    self.upImg.frame = CGRectMake(self.titleLabel.frame.origin.x, self.img.frame.origin.y + self.img.frame.size.height - kHeight * 20, kWidth * 20, kHeight * 20);
    
    self.upLabel.frame = CGRectMake(self.upImg.frame.origin.x + self.upImg.frame.size.width, self.upImg.frame.origin.y, self.titleLabel.frame.size.width - kWidth * 20, kHeight * 20);
    
    
}

-(void)setIllnessDetailModel:(KongWIllnessDetailModel *)illnessDetailModel
{
    if (_illnessDetailModel != illnessDetailModel) {
        [_illnessDetailModel release];
        _illnessDetailModel = [illnessDetailModel retain];
    }
    [self.img sd_setImageWithURL:[NSURL URLWithString:illnessDetailModel.thumb]];
    NSString *title = [illnessDetailModel.title stringByReplacingOccurrencesOfString:@"<font color=\"#00a0e9\">" withString:@""];
    title =  [title stringByReplacingOccurrencesOfString:@"</font>" withString:@""];
    self.titleLabel.text = title;
    
    self.upImg.image = [UIImage imageNamed:@"KongWiconfont-tubiao"];
    
    self.upLabel.text = [NSString stringWithFormat:@"%ld觉得很有用", illnessDetailModel.up];
    //关键字高亮
    NSString *str = [NSString stringWithFormat:@"%ld觉得很有用", illnessDetailModel.up];
    NSMutableAttributedString *titleStr = [[NSMutableAttributedString alloc]initWithString:str];
    
    NSRange range = [self.upLabel.text rangeOfString:[NSString stringWithFormat:@"%ld", illnessDetailModel.up]];
    [titleStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
    self.upLabel.attributedText = titleStr;
    
    
    
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
